<?php

require_once dirname(__FILE__) . '/../lib/sf_guard_userGeneratorConfiguration.class.php';
require_once dirname(__FILE__) . '/../lib/sf_guard_userGeneratorHelper.class.php';

/**
 * sf_guard_user actions.
 *
 * @package    virtualdelivery
 * @subpackage sf_guard_user
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class sf_guard_userActions extends autoSf_guard_userActions {

    public function executeActivate(sfWebRequest $request) {
        $usr_id = $request->getParameter('usr_id');
        try {
            $user = SfGuardUserPeer::retrieveByPK($usr_id);
            if (empty($user)) {
                throw new Exception('El usuario no existe.');
            }
            $active_state = 1;

            $user->setIsActive($active_state);
            $user->save();
        } catch (sfException $e) {
            sfContext::getInstance()->getUser()->setFlash('error', 'El usuario no existe.');
        }
        $this->redirect('@sf_guard_user');
    }

    public function executeDeactivate(sfWebRequest $request) {
        $usr_id = $request->getParameter('usr_id');
        try {
            $user = SfGuardUserPeer::retrieveByPK($usr_id);

            $inactive_state = 0;
            $user->setIsActive($inactive_state);
            $user->save();
        } catch (sfException $e) {
            sfContext::getInstance()->getUser()->setFlash('error', 'El usuario no existe.');
        }
        $this->redirect('@sf_guard_user');
    }

}
